<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pdf</title>
</head>

<body>
    <div id="back">返回</div>
    <input id="input" type="text">
    <div id="btn">生成</div>
    <script>
        const oBackBtn = document.getElementById('back')
        const oInput = document.getElementById('input')
        const oBtn = document.getElementById('btn')
        oBackBtn.onclick = () => {
            window.history.back()
        }
        oBtn.addEventListener('click', async () => {
            const text = oInput.value
            const response = await fetch(`http://localhost:9527/tools/url2pdf?url=${text}`);
            const blob = await response.blob();
            const url = window.URL.createObjectURL(blob);
            console.log(url);
            // 创建一个链接元素，模拟点击以下载 PDF
            const a = document.createElement('a');
            a.href = url;
            a.download = 'document.pdf';
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            window.URL.revokeObjectURL(url);
        })
    </script>
</body>

</html>